#ifndef WINCRITICAL_SECTION_H
#define WINCRITICAL_SECTION_H

#include "criticalsection.h"

class WinCriticalSection : public CriticalSection
{ 
public: 
	WinCriticalSection() 
	{ 
		InitializeCriticalSection(&m_csSafeAccess); 
	} 

	~WinCriticalSection()
	{ 
		DeleteCriticalSection(&m_csSafeAccess); 
	} 

	void Lock() 
	{ 
		EnterCriticalSection(&m_csSafeAccess); 
	} 

	void Unlock() 
	{ 
		LeaveCriticalSection(&m_csSafeAccess); 
	} 

private: 
	CRITICAL_SECTION  m_csSafeAccess; 
}; 


class AutoLockWinCriticalSection
{ 
public:
    __forceinline AutoLockWinCriticalSection(WinCriticalSection& cs) :
        m_cs(cs)
    {
        m_cs.Lock();
    }
    __forceinline ~AutoLockWinCriticalSection()
    {
        m_cs.Unlock();
    }

private: 
    WinCriticalSection& m_cs;

    // cannot copy or assign URLDownloadCallback
    AutoLockWinCriticalSection(const AutoLockWinCriticalSection&);
    AutoLockWinCriticalSection& operator=(const AutoLockWinCriticalSection&);
};

#endif